package org.ycx.doc.dao.auto;

import java.util.List;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.DeleteProvider;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectKey;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;
import org.ycx.doc.dao.model.DocGroupUser;
import org.ycx.doc.dao.model.DocGroupUserExample;

public interface DocGroupUserMapper {
    @SelectProvider(type=DocGroupUserSqlProvider.class, method="countByExample")
    long countByExample(DocGroupUserExample example);

    @DeleteProvider(type=DocGroupUserSqlProvider.class, method="deleteByExample")
    int deleteByExample(DocGroupUserExample example);

    @Delete({
        "delete from doc_group_user",
        "where GROUP_ID = #{groupId,jdbcType=INTEGER}",
          "and USER_ID = #{userId,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(@Param("groupId") Integer groupId, @Param("userId") Integer userId);

    @Insert({
        "insert into doc_group_user (USER_ID, ROLE)",
        "values (#{userId,jdbcType=INTEGER}, #{role,jdbcType=INTEGER})"
    })
    @SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="groupId", before=false, resultType=Integer.class)
    int insert(DocGroupUser record);

    @InsertProvider(type=DocGroupUserSqlProvider.class, method="insertSelective")
    @SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="groupId", before=false, resultType=Integer.class)
    int insertSelective(DocGroupUser record);

    @SelectProvider(type=DocGroupUserSqlProvider.class, method="selectByExample")
    @Results({
        @Result(column="GROUP_ID", property="groupId", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="USER_ID", property="userId", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="ROLE", property="role", jdbcType=JdbcType.INTEGER)
    })
    List<DocGroupUser> selectByExample(DocGroupUserExample example);

    @Select({
        "select",
        "GROUP_ID, USER_ID, ROLE",
        "from doc_group_user",
        "where GROUP_ID = #{groupId,jdbcType=INTEGER}",
          "and USER_ID = #{userId,jdbcType=INTEGER}"
    })
    @Results({
        @Result(column="GROUP_ID", property="groupId", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="USER_ID", property="userId", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="ROLE", property="role", jdbcType=JdbcType.INTEGER)
    })
    DocGroupUser selectByPrimaryKey(@Param("groupId") Integer groupId, @Param("userId") Integer userId);

    @UpdateProvider(type=DocGroupUserSqlProvider.class, method="updateByExampleSelective")
    int updateByExampleSelective(@Param("record") DocGroupUser record, @Param("example") DocGroupUserExample example);

    @UpdateProvider(type=DocGroupUserSqlProvider.class, method="updateByExample")
    int updateByExample(@Param("record") DocGroupUser record, @Param("example") DocGroupUserExample example);

    @UpdateProvider(type=DocGroupUserSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(DocGroupUser record);

    @Update({
        "update doc_group_user",
        "set ROLE = #{role,jdbcType=INTEGER}",
        "where GROUP_ID = #{groupId,jdbcType=INTEGER}",
          "and USER_ID = #{userId,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(DocGroupUser record);
}